/**
 * 
 */
package reco.db.validation;

import static com.google.common.base.Preconditions.checkNotNull;
import reco.db.Constraint;

public class MaxConstraint<T extends Comparable<T>> extends Constraint<T> {
    private final T max;

    public MaxConstraint(T maxValue) {
        super("max", "tooBig");
        this.max = checkNotNull(maxValue, "maxValue");
    }

    @Override
    public boolean validate(T value) {
        if (value == null) {
            return true;
        }
        return this.max.compareTo(value) >= 0;
    }

    @Override
    public Object[] getErrorArguments() {
        return new Object[] { this.max };
    }

}
